package com.example.hybridmobiledemo.view;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hybridmobiledemo.R;
import com.example.hybridmobiledemo.module.main.model.traffic.BusDetails;
import com.example.hybridmobiledemo.module.main.model.traffic.bean.Bus;

import java.util.List;


public class BusAdapter extends RecyclerView.Adapter<BusAdapter.ViewHolder> {
    private List<Bus> list;
    private Context context;

    public BusAdapter(Context context, List<Bus> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public BusAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.bus_item,parent,false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull BusAdapter.ViewHolder holder, int position) {
        Bus bus = list.get(position);
        holder.carName.setText("车辆名称：" +bus.getCarName());
        holder.currentSite.setText("当前站点：" +bus.getCarName());
        holder.nextSite.setText("下一站点：" +bus.getCarName());
        holder.image_bus.setImageResource(R.drawable.def);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, BusDetails.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        if(list != null){
            return list.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView carName,currentSite,nextSite;
        ImageView image_bus;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            carName = itemView.findViewById(R.id.carName);
            currentSite = itemView.findViewById(R.id.currentSite);
            nextSite = itemView.findViewById(R.id.nextSite);
            image_bus = itemView.findViewById(R.id.image_bus);

        }
    }
}
